<template>
  <div class="app-container">

    <el-form ref="form"   v-loading="isloading"  :model="form" :rules="rules" label-position="right" label-width="200px">
      <div class="title">
        自动化设置
      </div>
      <el-form-item prop="flashOrderCloseTime" label="限时抢购订单超过">
        <el-input-number v-model="form.flashOrderCloseTime" :min="0" label="分钟"></el-input-number>
        &nbsp;&nbsp;分钟未付款，订单自动关闭
      </el-form-item>
      <el-form-item prop="orderCloseTime" label="下单后超过">
        <el-input-number v-model="form.orderCloseTime" :min="0" label="分钟"></el-input-number>
        &nbsp;&nbsp;分钟未付款，订单自动关闭
      </el-form-item>
      <el-form-item prop="receiveCloseTime" label="发货超过">
        <el-input-number v-model="form.receiveCloseTime" :min="0" label="天"></el-input-number>
        &nbsp;&nbsp;天未确认收获，订单自动收货
      </el-form-item>
      <el-form-item prop="orderFinishTime" label="订单完成超过">
        <el-input-number v-model="form.orderFinishTime" :min="0" label="天"></el-input-number>
        &nbsp;&nbsp;自动结束交易，不能申请售后
      </el-form-item>
      <div class="title">
        其他设置
      </div>
      <el-form-item prop="smsWhenSend" label="订单短信通知">
        <el-switch v-model="form.smsWhenSend" active-color="#13ce66" inactive-color="#aaa">
        </el-switch>
        &nbsp;&nbsp;订单支付后系统发短信通知发货人
      </el-form-item>
      <el-form-item prop="provideInvoice" label="提供发票">
        <el-switch v-model="form.provideInvoice" active-color="#13ce66"  inactive-color="#aaa">
        </el-switch>
        &nbsp;&nbsp;开启后买家下单后可以索取发票
      </el-form-item>
      <div class="btns">
 <el-button type="primary" :loading="isSubmiting"  @click="doSubmit">保存提交</el-button>
    </div>
    </el-form>
    
     

  </div>
</template>
<script>
export default {
  data() {
    return {
      isSubmiting: false,
      isloading: true,
      form: {
        flashOrderCloseTime: 0,
        orderCloseTime: 0,
        receiveCloseTime: 0,
        orderFinishTime: 0,
        smsWhenSend: 0,
        provideInvoice: 0
      },
      rules: {
        flashsale_paytime: {
          required: true,
          message: ""
        },
        orderCloseTime: {
          required: true,
          message: ""
        },
        receiveCloseTime: {
          required: true,
          message: ""
        },
        orderFinishTime: {
          required: true,
          message: ""
        },
        smsWhenSend: {
          required: true,
          message: ""
        },
        provideInvoice: {
          required: true,
          message: ""
        }
      }
    };
  },
  created() {
    this.$post("/admin/sys_config/get_order_config")
      .then(data => {
        this.form = data;
        this.isloading = false;
      })
      .catch(_ => {
        this.isloading = false;
      });
  },
  methods: {
    doSubmit() {
      this.isSubmiting = true;
      this.$post("/admin/sys_config/save_order_config", this.form)
        .then(_ => {
          this.isSubmiting = false;
          this.$$notify();
        })
        .catch(_ => {
          this.isSubmiting = false;
        });
    }
  }
};
</script>

<style lang="scss" scoped>
.title {
  padding: 20px 0 20px 10px;
  border-bottom: 1px solid #eee;
  margin-bottom: 30px;
}
.btns {
  padding-left: 160px;
  padding-top: 40px;
}
</style>
